﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class MaximumEarliness : Objective
    {
        public MaximumEarliness()
            : base()
        {
        }

        public MaximumEarliness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        
        protected override void Logic()
        {
            int earliness = 0;
            int maximumEarliness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                if (order.DueDate > order.EndDate)
                {
                    earliness = order.DueDate - order.EndDate;
                    maximumEarliness = Math.Max(earliness, maximumEarliness);
                }
            }

            GeneratePerformanceRow();

            performance.Value = maximumEarliness;


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderDueDateValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
        }

        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Maximum Earliness";
                aboutInfo.Guid = new Guid("{22701748-07C2-45a5-8ED1-EE14EB9735A1}");
                aboutInfo.Description = Resources.MaximumEarlinessDescription;
                return aboutInfo;
            }
        }

    }
}
